<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>发送系统消息</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<script src="${ctx}/rs/js/jquery.validate.min.js"></script>
<script src="${ctx}/rs/js/jquery.form.js" type="text/javascript"></script>
</head>
<body>
<form id="form1" class="form-horizontal" action="${ctx}/message/save.htm" method="post">
      <div class="form-group">
        <label for="name" class="col-sm-2 control-label item ">标题：</label>
        <div class="col-sm-6  ">
          <input type="text" class="form-control " id="title" name="title"/>
        </div>
        <span class="help-block col-sm-4" id="valierr" style="color:#FF9966">*</span>
      </div>

	  <div class="form-group">
        <label for="name" class="col-sm-2 control-label item ">类型：</label>
        <div class="col-sm-6  ">
          <select class="form-control " id="type" name="type">
  			<option value="0" selected="selected">系统通知</option>
		  </select>
        </div>
      </div>
	  
	  <div class="form-group">
        <label for="name" class="col-sm-2 control-label item ">内容：</label>
        <div class="col-sm-6  ">
		  <textarea class="form-control" rows="3" id="content" name="content"/>
        </div>
        <span class="help-block col-sm-4" id="valierr" style="color:#FF9966">*</span>
      </div>
	  
      <div class="form-group">
        <div class="col-sm-10 text-center pt15">
		  <shiro:hasPermission name="message:save">
		     <button type="button" class="btn btn-primary btn-lg srt-btn active mr30" onclick="valiSubmit()">发送</button>
		     <button type="reset" class="btn btn-default btn-lg srt-btn active">重置</button>
          </shiro:hasPermission>
        </div>
      </div>

      <div class="form-group">
        <div class=" col-sm-10">
          <span id="error-text" style="color: #FF0000;"></span>
        </div>
      </div>
</form>


<script type="text/javascript" src="${ctx}/rs/js/bootstrapQ.min.js"></script>
<script src="${ctx}/rs/js/messages_zh.min.js"></script>
<script type="text/javascript">
	
	//初始化验证 start
    var form = $('#form1');
    form.validate({
		rules: {
			title: {
				maxlength: 50,
		        required: true
		    },
		    content: {
		    	maxlength: 500,
			    required: true
			}
		  },
		  highlight: function(element) {
			  $(element).closest('.form-group').removeClass('success').addClass('error');
		  },
		  success: function(element) {
			  element.text('OK!').addClass('valid')
		      .closest('.form-group').removeClass('error').addClass('success');
		  }
    });
    /** end */

	function valiSubmit() {
		if (form.valid()) {
			var data = $("#form1").serialize();      //获取表单多个控件的数据
			$(".unable").show();
			$.ajax({
                url: "${ctx}/message/save.htm",
                type: "post",
                data: data,
                success: function (text) {
                	if(!$('.unable').is(':hidden')){
                		$(".unable").hide();
                	}
               	    // 普通消息提示条
					bootstrapQ.msg({
						msg : '发送消息成功！',
						type : 'success',
						time : 2000
					});
					//触发隐藏确认的按钮，引用回调方法关闭窗口并刷新列表
					$("button.bsok").click();
                }
            });
		}
    }
       	 
	

</script>
</body>
</html>